package com.lxw.oa.service.serviceImpl;

import com.lxw.oa.entity.SystemLog;
import com.lxw.oa.entity.User;
import com.lxw.oa.mapper.BaseMapper;
import com.lxw.oa.mapper.RoleMapper;
import com.lxw.oa.mapper.UserMapper;
import com.lxw.oa.service.BaseService;
import com.lxw.oa.service.UserService;
import com.lxw.oa.util.BootstrapTable;
import com.lxw.oa.util.StringUtil;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void userImgAdd(String image, String userName) {
        userMapper.userImgAdd(image,userName);
    }

    @Override
    public void userImgDel(String userName) {
        userMapper.userImgDel(userName);
    }

    @Override
    public List<String> userImgGet(String userName) {
        return  userMapper.userImgGet(userName);
    }

    @Override
    public void userImgsAdd(String image) {
        int index1=image.indexOf("image");
        int index2=image.indexOf("base64");
        String type=image.substring(index1+6,index2-1);
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(date);
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String  userName = user.getName();
        userMapper.userImgsAdd(userName,image,dateString,type);
    }

    @Override
    public List<String> userImgsGet() {
        return  userMapper.userImgsGet();
    }

    @Override
    public List<HashMap> getInformation(String name) { return userMapper.getInformation(name); }
}
